#include <stddef.h>           /* needed for definition of NULL */
#include <stdio.h>
#include "Common.h"
#include "LCD.h"
#include "Gdi.h"

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       GUI_DispNextLine
*/
void GUI_DispNextLine(void) {
    GUI_LOCK();
    GUI_Context.DispPosY += GUI_GetFontDistY();
    GUI_Context.DispPosX  = GUI_Context.LBorder;
    GUI_UNLOCK();
}

/*********************************************************************
*
*       GL_DispChar
*/
void GL_DispChar(WORD c) {
    /* check for control characters */
    if (c == '\n') {
        GUI_DispNextLine();
    } else {
        if (c != '\r') {
            GUI_LOCK();
            GUI_Context.pAFont->pfDispChar(c);
            GUI_UNLOCK();
        }
    }
}

/*********************************************************************
*
*       GUI_GetYAdjust
*
* Returns adjustment in vertical (Y) direction
*
* Note: The return value needs to be subtracted from
*       the y-position of the character.
*/
int GUI_GetYAdjust(void) {
    int r = 0;
    GUI_LOCK();
    switch (GUI_Context.TextAlign & GUI_TA_VERTICAL) {
        case GUI_TA_BOTTOM:
            r = GUI_Context.pAFont->YSize - 1;
        break;
        case GUI_TA_VCENTER:
            r = GUI_Context.pAFont->YSize / 2;
        break;
        case GUI_TA_BASELINE:
            r = GUI_Context.pAFont->YSize / 2;
    }
    GUI_UNLOCK();
    return r;
}

/*********************************************************************
*
*       GUI_GetFontDistY
*/
int GUI_GetFontDistY(void) {
    int r;
    GUI_LOCK();
    r = GUI_Context.pAFont->YDist;
    GUI_UNLOCK();
    return r;
}

/*********************************************************************
*
*       GUI_GetCharDistX
*/
int GUI_GetCharDistX(WORD c) {
    int r;
    GUI_LOCK();
    r = GUI_Context.pAFont->pfGetCharDistX(c);
    GUI_UNLOCK();
    return r;
}

/*************************** End of file ****************************/
